package edu.bucknell.gaugetest;


import android.os.Bundle;
import android.app.Activity;
import android.widget.Button;
import android.widget.ImageView;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;

/**
 *  Notes for image start and stop values
 *  180 amps: 0 = 41.5 degrees 180= 313 Degrees
 * @author edash
 *
 */
public class MainActivity extends Activity {

	Button button;
	Gauge myView;
	Gauge myView2;
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		

		myView = (Gauge)findViewById(R.id.gauge);
		myView2 = (Gauge)findViewById(R.id.gauge2);

		//Gauge
		Bitmap guageOriginal = BitmapFactory.decodeResource(this.getResources(), R.drawable.auxbatcurrent400);
		
		//Needle
		Bitmap needleOriginal = BitmapFactory.decodeResource(this.getResources(), R.drawable.needle400);
		
		

		myView.setBackground(guageOriginal);
		myView.setNeedle(needleOriginal);
		myView2.setBackground(guageOriginal);
		myView2.setNeedle(needleOriginal);
		myView.setBounds((float)31.5, (float)332.5, (float)0, (float)50);
		
		new Thread(new Runnable() {
	        public void run() {
	               //loop(myView);
	              // myView.setNeedleDestination((float)-.5);
	        	myView.setTargetVal((float)10);
	        }
			}).start();
//		new Thread(new Runnable() {
//	        public void run() {
//	                loop(myView2);
//	               // myView.setNeedleDestination((float)214);
//	        }
//			}).start();
//		System.out.println("Completed On Create");
		
	}

	// Main and Aux Battery Current
	// i = 31.5
	// i = 332.5
	
	//speed
	// 61
	// 302.5
	
	//Charge Removed
	//214
	//323
	
	// Voltages need to rotate the otehr direction to go up but that should be fine
	//Aux Voltage
	// -162
	// -13
	//
	
	//Main Voltage
	// -179.5
	// +.5

	
	private void loop(Gauge gauge){
//		while(true){
//			gauge.setNeedleDestination((float) (Math.random()*360));
//			try {
//				Thread.sleep(1500);
//			} catch (InterruptedException e1) {
//				// TODO Auto-generated catch block
//				e1.printStackTrace();
//			}
//		}
		for (float i = 170; i <370; i += 2){
			gauge.setNeedleDestination(i);
			System.out.println(i);
			try {
				Thread.sleep(1500);
			} catch (InterruptedException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
		}

		
		}
		
	}
	
}